#ifndef _ZY_BUTTON_H
#define _ZY_BUTTON_H
#include "stdint.h"
#include "stdbool.h"
#include "GlitchFilter.h"
typedef enum 
{
	Button_down=0,
	Button_up=1
}Button_Status_Type;

#define MSG_Get_PIN_Key        0x01   //查看按键引脚状态

typedef uint8_t (*Button_Pin_cb)(uint8_t msg, uint8_t arg_int);
typedef void (*ButtonEvent_cb)(uint8_t button_id);
typedef struct
{
	bool Enable;
	ButtonEvent_cb event_cb;
}ZY_BUTTON_Event_t;
typedef struct
{
	uint16_t LongPress_time;
	uint32_t time;
}Button_Time_t;
typedef struct
{
	Button_Status_Type last_status;
	Button_Status_Type status;
}Button_Status_t;
typedef struct 
{
    Button_Pin_cb        pin_cb;             //引脚回调
	  ZY_BUTTON_Event_t    click;              //点击事件
	  ZY_BUTTON_Event_t    key_up;             //释放按键事件
	  ZY_BUTTON_Event_t    key_down;           //按下按键事件
	  ZY_BUTTON_Event_t    LongPress;          //长按按键事件
	  Button_Time_t        time;               //事件配置
    Glitch_Filter_t      filter;
    Button_Status_t      status;
    uint8_t              id;                 //按键ID	
}ZY_BUTTON_t;
void ZY_Button_Register_f(ZY_BUTTON_t *tcb,Button_Pin_cb pin_cb,uint16_t time,uint8_t id); //按键注册 
void ZY_ButtonRegister_EventClick(ZY_BUTTON_t *tcb,ButtonEvent_cb cb);                     //按键点击回调注册
void ZY_ButtonRegister_EventLongPress(ZY_BUTTON_t *tcb,ButtonEvent_cb cb,uint16_t time);   //按键长按回调注册
void ZY_ButtonRegister_EventKeyUP(ZY_BUTTON_t *tcb,ButtonEvent_cb cb);      //按键释放回调注册
void ZY_ButtonRegister_EventKeyDown(ZY_BUTTON_t *tcb,ButtonEvent_cb cb);    //按键按下回调注册
void ZY_Button_Process(ZY_BUTTON_t *tcb,uint16_t time);    //按键轮询
#endif
